package com.hdjk.view.callback;

import com.hdjk.view.entity.BannerEntity;
import com.lst.projectlib.entity.Msg;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import okhttp3.Response;

/**
 * Created by sxy on 2017/11/2.
 */

public abstract class GetBannerListCallBack extends MsgCallBack {
    @Override
    public Msg parseNetworkResponse(Response response, int i) throws Exception {
        Msg msg = super.parseNetworkResponse(response, i);
        JSONArray array = (JSONArray) msg.getData();
        if (array!=null) {
            List<BannerEntity> list = new ArrayList<>();
            if (array != null && array.length() > 0) {
                for (int j = 0; j < array.length(); j++) {
                    JSONObject jsonObject = array.getJSONObject(j);
                    BannerEntity entity = new BannerEntity();
                    if (!jsonObject.isNull("EditType")) {
                        entity.setEditType(jsonObject.getString("EditType"));
                    }
                    if (!jsonObject.isNull("ParentId")) {
                        entity.setParentId(jsonObject.getInt("ParentId"));
                    }
                    if (!jsonObject.isNull("TypeCode")) {
                        entity.setTypeCode(jsonObject.getInt("TypeCode"));
                    }
                    if (!jsonObject.isNull("TypeName")) {
                        entity.setTypeName(jsonObject.getString("TypeName"));
                    }
                    if (!jsonObject.isNull("Name")) {
                        entity.setName(jsonObject.getString("Name"));
                    }
                    if (!jsonObject.isNull("Value")) {
                        entity.setValue(jsonObject.getString("Value"));
                    }
                    if (!jsonObject.isNull("Value2")) {
                        entity.setValue2(jsonObject.getString("Value2"));
                    }
                    if (!jsonObject.isNull("Value3")) {
                        entity.setValue3(jsonObject.getString("Value3"));
                    }
                    if (!jsonObject.isNull("Order")) {
                        entity.setOrder(jsonObject.getInt("Order"));
                    }
                    if (!jsonObject.isNull("Id")) {
                        entity.setId(jsonObject.getString("Id"));
                    }
                    list.add(entity);
                }
            }
            msg.setData(list);
        }
        return msg;
    }
}
